package com.hjm.project.agentInfo.profitSbOrder.controller;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.hjm.common.utils.DateUtils;
import com.hjm.common.utils.StringUtils;
import com.hjm.common.utils.Utils;
import com.hjm.common.utils.security.ShiroUtils;
import com.hjm.framework.config.CustomConfig;
import com.hjm.project.agentInfo.profitSbOrder.domain.AgentPaiWVO;
import com.hjm.project.agentInfo.profitSbOrder.utils.OrderUtils;
import com.hjm.project.agentInfo.profitSbOrder.utils.PublicTypeUtils;
import com.hjm.project.job.task.service.IJobTaskService;
import com.hjm.project.merPaid.merPaid.domain.MerPaid;
import com.hjm.project.terminal.manufacturer.service.IManufacturerService;
import com.yxhd.encrypt.EncryptUtils;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;
import com.hjm.framework.aspectj.lang.annotation.Log;
import com.hjm.framework.aspectj.lang.enums.BusinessType;
import com.hjm.project.agentInfo.profitSbOrder.domain.ProfitSbOrder;
import com.hjm.project.agentInfo.profitSbOrder.service.IProfitSbOrderService;
import com.hjm.framework.web.controller.BaseController;
import com.hjm.framework.web.domain.AjaxResult;
import com.hjm.common.utils.poi.ExcelUtil;
import com.hjm.framework.web.page.TableDataInfo;

import javax.annotation.Resource;

/**
 * 分润单号Controller
 * 
 * @author LOVE
 * @date 2020-11-27
 */
@Controller
@RequestMapping("/agentInfo/profitSbOrder")
public class ProfitSbOrderController extends BaseController
{
    private String prefix = "agentInfo/profitSbOrder";

    @Autowired
    private IProfitSbOrderService profitSbOrderService;
    @Resource
    private IManufacturerService manufacturerService;


    @Autowired
    private IJobTaskService jobTaskService;
    @RequiresPermissions("agentInfo:profitSbOrder:view")
    @GetMapping()
    public String profitSbOrder()
    {
        return prefix + "/profitSbOrder";
    }

    /**
     * 查询分润单号列表
     */
    @RequiresPermissions("agentInfo:profitSbOrder:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(ProfitSbOrder profitSbOrder)
    {
        startPage();
        List<ProfitSbOrder> list = profitSbOrderService.selectProfitSbOrderList(profitSbOrder);
        return getDataTable(list);
    }

    /**
     * 导出分润单号列表
     */
    @RequiresPermissions("agentInfo:profitSbOrder:export")
    @Log(title = "分润单号", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(ProfitSbOrder profitSbOrder)
    {
        List<ProfitSbOrder> list = profitSbOrderService.selectProfitSbOrderList(profitSbOrder);
        ExcelUtil<ProfitSbOrder> util = new ExcelUtil<ProfitSbOrder>(ProfitSbOrder.class);
        return util.exportExcel(list, "profitSbOrder");
    }

    /**
     * 新增分润单号
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存分润单号
     */
    @RequiresPermissions("agentInfo:profitSbOrder:add")
    @Log(title = "分润单号", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(ProfitSbOrder profitSbOrder)
    {
        return toAjax(profitSbOrderService.insertProfitSbOrder(profitSbOrder));
    }

    /**
     * 修改分润单号
     */
    @GetMapping("/edit/{ordernumber}")
    public String edit(@PathVariable("ordernumber") String ordernumber, ModelMap mmap)
    {
        ProfitSbOrder profitSbOrder = profitSbOrderService.selectProfitSbOrderById(ordernumber);
        mmap.put("profitSbOrder", profitSbOrder);
        return prefix + "/edit";
    }

    /**
     * 修改保存分润单号
     */
    @RequiresPermissions("agentInfo:profitSbOrder:edit")
    @Log(title = "分润单号", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(ProfitSbOrder profitSbOrder)
    {
        return toAjax(profitSbOrderService.updateProfitSbOrder(profitSbOrder));
    }

    /**
     * 删除分润单号
     */
    @RequiresPermissions("agentInfo:profitSbOrder:remove")
    @Log(title = "分润单号", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(profitSbOrderService.deleteProfitSbOrderByIds(ids));
    }

    /**
     * 导出明细
     */
    @RequiresPermissions("agentInfo:profitSbOrder:exportDetailExcel")
    @Log(title = "分润单号", businessType = BusinessType.EXPORT)
    @PostMapping("/exportDetailExcel")
    @ResponseBody
    public AjaxResult exportDetailExcel(ProfitSbOrder profitSbOrder) throws Exception {
        profitSbOrderService.exportDetailExcel(profitSbOrder,this.getSysUser().getLoginName());
        return AjaxResult.success("请前往综合管理/下载队列查看下载详情");
    }

    /**
     * 查看详情
     */
    @GetMapping("/looksDetails/{orderNumber}")
    public String looksDetails(@PathVariable("orderNumber") String orderNumber, ModelMap map)
    {
        map.put("orderNumber", orderNumber);
        return prefix + "/looksDetails";
    }

    /**
     * 订单详情
     */
    @RequiresPermissions("agentInfo:profitSbOrder:looksDetails")
    @PostMapping("/detailList")
    @ResponseBody
    public TableDataInfo detailList(@RequestParam Map<String,Object> params) throws Exception
    {
        startPage();
        List<Map<String,Object>> list = profitSbOrderService.getUnPayPageList(params);
        return getDataTable(list);
    }

    /**
     * 删除分润单号
     */
    @Log(title = "分润单号", businessType = BusinessType.DELETE)
    @PostMapping( "/examineAgent")
    @ResponseBody
    public AjaxResult examineAgent(String ordernumber)
    {
        return toAjax(profitSbOrderService.examineAgent(ordernumber));
    }

    @RequiresPermissions("agentInfo:profitSbOrder:unPayList")
    @GetMapping("/unPayList")
    public String unPayList(@RequestParam(required = false) Map<String,String> params,ModelMap mmap)
    {
        mmap.put("mindDate", DateUtils.getDate());
        mmap.put("maxDate", DateUtils.getDate());
        if (StringUtils.isNotBlank(params.get("ordernumber"))){
            mmap.put("ordernumber",params.get("ordernumber"));
            mmap.put("type",params.get("ordernumber"));
            mmap.put("searchType",params.get("searchType"));
        }else{
            mmap.put("ordernumber","");
            mmap.put("type","");
            mmap.put("searchType","");
        }
        Map<String,Object> orderMap=new HashMap<>();
        orderMap.put("indate", Utils.formateDate(0));
        orderMap.put("status","2,3");
        List<Map<String,Object>> list=profitSbOrderService.getDateOrdernumber(orderMap);
        mmap.put("list",list);
        return prefix + "/unPayList";
    }

    /**
     * 未出款数据列表
     */
    @RequiresPermissions("agentInfo:profitSbOrder:unPayList")
    @PostMapping("/unPayList")
    @ResponseBody
    public TableDataInfo unPayList(@RequestParam Map<String,Object> params) throws Exception
    {
        //查询未出款的数据
        params.put("settle_state",0);
        //0-未出款数据菜单、1-所有出款数据
        if(null==params.get("searchType")) {
            params.put("searchType",0);
        }

        String money = String.valueOf(params.get("lower_money"));
        if (StringUtils.isNotBlank(money)){
            Boolean strResult = money.matches("-?[0-9]+.*[0-9]*");
            if (!strResult){
                params.remove("lower_money");
                params.put("no_date","1");
            }
        }
        Map<String, Object> unPayPageListSum = profitSbOrderService.getUnPayPageListSum(params);
        startPage();
        List<Map<String,Object>> list = profitSbOrderService.getUnPayPageList(params);
        return getDataTable(list,unPayPageListSum);
    }

    /**
     * 添加订单
     */
    @GetMapping("/addOrder")
    public String addOrder()
    {
        return prefix + "/addOrder";
    }

    /**
     * 新增保存分润单号
     */
    @RequiresPermissions("agentInfo:profitSbOrder:addOrder")
    @Log(title = "添加订单", businessType = BusinessType.INSERT)
    @PostMapping("/addOrder")
    @ResponseBody
    public AjaxResult addOrder(String type)
    {
        Map<String,Object> params=new HashMap<>();
        params.put("ordertype",type);
        params.put("add_bills_person",this.getSysUser().getLoginName());
        return profitSbOrderService.saveOrder(params);
    }

    /**
     * 选择填单
     */
    @GetMapping("/fillBill")
    public String fillBill(ModelMap mmap)
    {
        Map<String,Object> orderMap=new HashMap<>();
        orderMap.put("indate", Utils.formateDate(0));
        orderMap.put("state","2");
        List<Map<String,Object>> list=profitSbOrderService.getDateOrdernumber(orderMap);
        mmap.put("lists",list);
        return prefix + "/fillBill";
    }


    /**
     * 新增保存分润单号
     */
    @RequiresPermissions("agentInfo:profitSbOrder:fillBill")
    @Log(title = "分润单号", businessType = BusinessType.INSERT)
    @PostMapping("/fillBill")
    @ResponseBody
    public AjaxResult fillBill(@RequestParam Map<String,Object> params)
    {
        if(StringUtils.isBlank(String.valueOf(params.get("ordernumber")))){
            return AjaxResult.error("未选择填单数据");
        }
        profitSbOrderService.saveBatchOrder(params,null,1);
        return toAjax(1);
    }

    /**
     * 一键填单
     */
    @GetMapping("/allOrder")
    public String allOrder(@RequestParam Map params, ModelMap mmap) {
        Map<String,Object> orderMap=new HashMap<>();
        orderMap.put("indate", Utils.formateDate(0));
        orderMap.put("state","2");
        List<Map<String,Object>> list=profitSbOrderService.getDateOrdernumber(orderMap);
        mmap.put("lists",list);
        mmap.put("params", JSONObject.toJSONString(params));
        return prefix + "/allOrder";
    }


    /**
     * 保存一键填单
     */
    @RequiresPermissions("agentInfo:profitSbOrder:fillBill")
    @Log(title = "一键填单", businessType = BusinessType.INSERT)
    @PostMapping("/saveAllOrder")
    @ResponseBody
    public AjaxResult saveAllOrder(@RequestParam Map<String,String> params) {
        Map paramsValue = JSONObject.parseObject(params.get("params"), Map.class);
        paramsValue.put("ordernumber",params.get("ordernumber"));
        if(StringUtils.isBlank(params.get("ordernumber"))){
            return AjaxResult.error("未选择订单编号");
        }
        try{
            profitSbOrderService.saveAllOrder(paramsValue);
            return success();
        }catch (Exception e){
            throw e;
        }
    }



    /**
     * 填单页面跳转
     */
    @GetMapping("/batchBill")
    public String batchBill(@RequestParam String orderNo,@RequestParam String[] ids,ModelMap mmap) {

        //通过主键获取流水


        Map<String,Object> paramMap=new HashMap<>();
        paramMap.put("ordernumber",orderNo);
        //查询订单信息
        Map<String,Object> orderMap=profitSbOrderService.getOrderOne(paramMap);
        if (null==orderMap){
            mmap.put("money","0");
            mmap.put("orderMap",orderMap);
            mmap.put("ableSize","0");
            mmap.put("unableSize","0");
            mmap.put("ableIds","");
            return prefix + "/batchBill";
        }
        //订单性质
        String orderType=String.valueOf(orderMap.get("ORDERTYPE"));
        paramMap.put("settle_state",0);
        paramMap.put("ids",ids);
        paramMap.put("isIds","isIds"); //标识是用id进行in查询
        //有效的
        List<Map<String,Object>> ableList=new ArrayList<>();
        //无效的
        List<Map<String,Object>> unableList=new ArrayList<>();
        //保存有效的ID
        String ableIds="";
        //总金额
        BigDecimal money = new BigDecimal("0");
        BigDecimal tranddelMax=new BigDecimal(CustomConfig.getTranddelMax());
        List<Map<String,Object>> upList=profitSbOrderService.getUnPayListById(paramMap);
        for (Map<String,Object> tmp : upList){
            String accountType=tmp.get("NATURE")+"";
            if (orderType.equals(accountType)){
                //校验金额是否超过二十万
                BigDecimal tmpMoney=new BigDecimal(tmp.get("MONEY").toString());
                //小于等于
                if (tmpMoney.compareTo(tranddelMax)<1){
                    money=money.add(tmpMoney);
                    ableList.add(tmp);
                    ableIds+=("".equals(ableIds)?tmp.get("SETTLE_SERIAL").toString():","+tmp.get("SETTLE_SERIAL").toString());
                }else{
                    unableList.add(tmp);
                }
            }else{
                unableList.add(tmp);
            }
        }
        int ableSize=ableList.size();
        int unableSize=unableList.size();

        mmap.put("money",money);
        mmap.put("ableList",ableList);
        mmap.put("unableList",unableList);
        mmap.put("orderMap",orderMap);
        mmap.put("ableSize",ableSize);
        mmap.put("unableSize",unableSize);
        mmap.put("ableIds",ableIds);
        return prefix + "/batchBill";
    }
    /**
     * 保存填单
     */
    @RequiresPermissions("agentInfo:profitSbOrder:batchBill")
    @Log(title = "保存填单", businessType = BusinessType.INSERT)
    @PostMapping("/batchBill")
    @ResponseBody
    public AjaxResult batchBill(@RequestParam String ordernumber,@RequestParam String ableIds,@RequestParam Long ableSize) throws Exception
    {
        if (ableSize.equals(0L)){
            return AjaxResult.error("无出款数据");
        }
        String[] ableIdss=ableIds.split(",");
        String[] ids=new String[ableIdss.length];
        for (int i=0;i<ableIdss.length;i++){
            ids[i] = ableIdss[i];
        }
        int result=profitSbOrderService.saveBatchOrder(ordernumber,ids,0);
        return toAjax(result);
    }
    /**
     * 冻结出款
     */
    @GetMapping("/frozen")
    public String frozen(@RequestParam String ids,ModelMap mmap)
    {
        mmap.put("ids",ids);
        return prefix + "/frozen";
    }
    /**
     * 冻结出款
     */
    @RequiresPermissions("agentInfo:profitSbOrder:frozen")
    @Log(title = "冻结出款", businessType = BusinessType.INSERT)
    @PostMapping("/frozen")
    @ResponseBody
    public AjaxResult frozen(@RequestParam String ids,@RequestParam String remarks) throws Exception
    {
        String[] ableIdss=ids.split(",");

        Map<String,Object> paramMap=new HashMap<>();
        paramMap.put("adminname",this.getSysUser().getLoginName());
        paramMap.put("remarks",remarks);
        return profitSbOrderService.saveFrozen(ableIdss,paramMap);
    }

    @RequiresPermissions("agentInfo:profitSbOrder:examlist")
    @GetMapping("/examlist")
    public String examlist()
    {
        return prefix + "/examlist";
    }

    /**
     * 审核单
     */
    @RequiresPermissions("agentInfo:profitSbOrder:examlist")
    @PostMapping("/examlist")
    @ResponseBody
    public TableDataInfo examlist(@RequestParam Map<String,Object> params) throws Exception
    {
        startPage();
        params.put("state","3");
        List<Map<String,Object>> list = profitSbOrderService.getOrderPageList(params);
        return getDataTable(list);
    }

    @Log(title = "订单审核", businessType = BusinessType.UPDATE)
    @PostMapping( "/auditOrder")
    @ResponseBody
    public AjaxResult auditOrder(String id) throws Exception
    {
        Map params=new HashMap(16);
        params.put("id",id);
        params.put("nowState",3);
        params.put("beForState",1);
        Map<String, String> data = profitSbOrderService.auditOrder(params);
        AjaxResult ajaxResult = OrderUtils.sendOrder(JSONObject.toJSONString(data));
        if (ajaxResult.get("code").toString().equals("200")) {
            profitSbOrderService.auditOrderError(params);
        }
        return ajaxResult;
    }

    @RequiresPermissions("agentInfo:profitSbOrder:payList")
    @GetMapping("/payList")
    public String payList(@RequestParam(required = false) Map<String,String> params,ModelMap mmap) {
        if (StringUtils.isNotBlank(params.get("ordernumber"))){
            mmap.put("ordernumber",params.get("ordernumber"));
        }else{
            mmap.put("ordernumber","");
        }
        return prefix + "/payList";
    }

    /**
     * 审核单
     */
    @RequiresPermissions("agentInfo:profitSbOrder:payList")
    @PostMapping("/payList")
    @ResponseBody
    public TableDataInfo payList(@RequestParam Map<String,Object> params) throws Exception
    {
        startPage();
        //0-未出款数据菜单、1-所有出款数据
        params.put("searchType",1);
        List<Map<String,Object>> list = profitSbOrderService.getUnPayPageList(params);
        return getDataTable(list);
    }

    /**
     * 导出终端达标明细
     */
    @Log(title = "分润出款数据导出", businessType = BusinessType.EXPORT)
    @PostMapping("/exportPayList")
    @ResponseBody
    public AjaxResult export(@RequestParam Map<String,Object> params) {
        params.put("ADD_MAN", ShiroUtils.getLoginName());
        profitSbOrderService.exportPayList(params);
        return AjaxResult.success("操作成功，前往综合管理-下载队列查看");
    }



    /**
     * 导出分润单号列表
     */
    @PostMapping("/payExport")
    @ResponseBody
    public AjaxResult payExport(@RequestParam Map<String,Object> params)
    {
        profitSbOrderService.getUnPayPageExport(params,this.getSysUser().getLoginName());
        return AjaxResult.success("操作成功，前往下载队列查看");
    }

    /**
     * 标记成功
     */
    @RequiresPermissions("agentInfo:profitSbOrder:signSuccess")
    @Log(title = "标记成功", businessType = BusinessType.DELETE)
    @PostMapping( "/signSuccess")
    @ResponseBody
    public AjaxResult signSuccess(String ids)
    {
        Map<String,Object> paramMap=new HashMap<>();
        paramMap.put("ids",ids);
        paramMap.put("adminname",this.getSysUser().getLoginName());
        return profitSbOrderService.signSuccess(paramMap);
    }

    /**
     * 标记失败
     */
    @GetMapping("/signFail")
    public String signFail(@RequestParam Map<String,Object> paramMap,ModelMap mmap)
    {
        //查询指定的出款数据
        paramMap.put("searchType",2);
        String ids = String.valueOf(paramMap.get("ids"));
        String[] split = ids.split(",");
        paramMap.put("ids",split);
        List<Map<String,Object>> merMapList=profitSbOrderService.getUnpayListByOrder(paramMap);
        HashMap<Object, Object> merMap = new HashMap<>();
        StringBuffer serialBuffer = new StringBuffer();
        int status = 0;
        for (Map<String, Object> map : merMapList) {
            serialBuffer.append(",").append(map.get("SETTLE_SERIAL"));
            if (!"0".equals(String.valueOf(map.get("STATUS"))) && !"1".equals(String.valueOf(map.get("STATUS")))){
                status = Integer.parseInt(String.valueOf(map.get("STATUS")));
            }
        }
        merMap.put("SETTLE_SERIAL",serialBuffer.toString().substring(1,serialBuffer.length()));
        merMap.put("STATUS",status);
        mmap.put("merMap",merMap);
        return prefix + "/signFail";
    }

    /**
     * 标记失败
     */
    @RequiresPermissions("agentInfo:profitSbOrder:signFail")
    @Log(title = "标记失败", businessType = BusinessType.DELETE)
    @PostMapping( "/signFail")
    @ResponseBody
    public AjaxResult signFail(@RequestParam Map<String,Object> paramMap)
    {
        String status=String.valueOf(paramMap.get("status"));
        if (!"0".equals(status) && !"1".equals(status)){
            return AjaxResult.error("当前出款数据不能标记为失败");
        }
        paramMap.put("adminname",this.getSysUser().getLoginName());
        String id = paramMap.get("id").toString();
        String[] split = id.split(",");
        paramMap.put("ableIds",split);
        return profitSbOrderService.saveSignFail(paramMap);
    }


    @RequiresPermissions("agentInfo:profitSbOrder:errorPayList")
    @GetMapping("/errorPayList")
    public String errorPayList()
    {
        return prefix + "/errorPayList";
    }

    /**
     * 出款失败数据
     */
    @RequiresPermissions("agentInfo:profitSbOrder:errorPayList")
    @PostMapping("/errorPayList")
    @ResponseBody
    public TableDataInfo errorPayList(@RequestParam Map<String,Object> params) throws Exception
    {
        startPage();
        //0-未出款数据菜单、1-所有出款数据、2-出款失败
        params.put("searchType",2);
        params.put("settle_state",-2);
        List<Map<String,Object>> list = profitSbOrderService.getUnPayPageList(params);
        return getDataTable(list);
    }

    /**
     * 同步结算账户信息
     */
    @GetMapping("/changeAccounts/{settleSerial}")
    public String changeAccounts(@PathVariable("settleSerial") String settleSerial, ModelMap mmap) throws Exception
    {
        Map acMap = profitSbOrderService.getApAc(settleSerial);
        if (acMap==null){
            acMap=new HashMap(16);
            acMap.put("S2" , "");
            acMap.put("S3" ,"");
            acMap.put("settle_serial", settleSerial);
            mmap.put("acMap", acMap);
            return prefix + "/changeAccounts";
        }
        acMap.put("S2" , EncryptUtils.getDecrypt(acMap.get("S2") == null ? "" : acMap.get("S2")+""));
        acMap.put("S3" ,EncryptUtils.getDecrypt(acMap.get("S3") == null ? "" : acMap.get("S3")+""));
        acMap.put("settle_serial", settleSerial);
        mmap.put("acMap", acMap);
        return prefix + "/changeAccounts";
    }

    /**
     * 标记失败
     */
    @RequiresPermissions("agentInfo:profitSbOrder:changeAccounts")
    @Log(title = "同步结算账户信息", businessType = BusinessType.DELETE)
    @PostMapping( "/changeAccounts")
    @ResponseBody
    public AjaxResult changeAccounts(@RequestParam Map<String,Object> map) throws Exception
    {
        return profitSbOrderService.changeAccounts(map);
    }

    /**
     * 一键转单
     */
    @GetMapping("/transFo")
    public String transFo(@RequestParam Map<String,Object> paramMap,ModelMap mmap)
    {
        String idStr=String.valueOf(paramMap.get("ids"));
        //查询今日单号
        Map<String,Object> orderMap=new HashMap<>();
        orderMap.put("indate", Utils.formateDate(0));
        orderMap.put("state","0");
        List<Map<String,Object>> list=profitSbOrderService.getDateOrdernumber(orderMap);
        mmap.put("list", list);
        mmap.put("idValue", idStr);
        String [] ids = idStr.split(",");
        StringBuffer nownumbers = new StringBuffer();
        //根据选中出款失败数据id 查询单号
        List<String> nList = profitSbOrderService.getAllAgentPaidNumber(ids);
        for (int i = 0;i<nList.size();i++){
            String orderNumber = nList.get(i);
            if (StringUtils.isNotBlank(orderNumber)){
                nownumbers.append(",").append(orderNumber);
            }
        }
        if (nownumbers.length() > 0){
            mmap.put("nownumbers",nownumbers.toString().substring(1,nownumbers.length()));
        }
        return prefix + "/transFo";
    }

    /**
     * 一键转单
     */
    @RequiresPermissions("agentInfo:profitSbOrder:transFo")
    @Log(title = "一键转单", businessType = BusinessType.DELETE)
    @PostMapping( "/transFo")
    @ResponseBody
    public AjaxResult transFo(@RequestParam Map<String,String> paramMap)
    {
        return profitSbOrderService.saveTransFo(paramMap);
    }

    @RequiresPermissions("agentInfo:profitSbOrder:frozenPayList")
    @GetMapping("/frozenPayList")
    public String frozenPayList()
    {
        return prefix + "/frozenPayList";
    }

    /**
     * 冻结出款数据
     */
    @RequiresPermissions("agentInfo:profitSbOrder:frozenPayList")
    @PostMapping("/frozenPayList")
    @ResponseBody
    public TableDataInfo frozenPayList(@RequestParam Map<String,Object> params) throws Exception
    {
        startPage();
        //0-未出款数据菜单、1-所有出款数据、2-出款失败
        params.put("status",-3);//冻结数据
        params.put("searchType",1);//0-未出款数据菜单、1-所有出款数据
        List<Map<String,Object>> list = profitSbOrderService.getUnPayPageList(params);
        return getDataTable(list);
    }

    /**
     * 冻结出款
     */
    @GetMapping("/thaw")
    public String thaw(@RequestParam String ids,ModelMap mmap)
    {
        mmap.put("ids",ids);
        return prefix + "/thaw";
    }
    /**
     * 冻结出款
     */
    @RequiresPermissions("agentInfo:profitSbOrder:thaw")
    @Log(title = "出款解冻", businessType = BusinessType.INSERT)
    @PostMapping("/thaw")
    @ResponseBody
    public AjaxResult thaw(@RequestParam String ids,@RequestParam String remarks) throws Exception
    {
        if ("".equals(remarks)|| null == remarks){
            return AjaxResult.error("解冻原因不能为空");
        }
        String[] ableIdss=ids.split(",");

        Map<String,Object> paramMap=new HashMap<>();
        paramMap.put("adminname",this.getSysUser().getLoginName());
        paramMap.put("remarks",remarks);
        return profitSbOrderService.saveThaw(ableIdss,paramMap);
    }

    @RequiresPermissions("agentInfo:profitSbOrder:historyList")
    @GetMapping("/historyList")
    public String historyList()
    {
        return prefix + "/historyList";
    }

    /**
     * 出款失败数据
     */
    @RequiresPermissions("agentInfo:profitSbOrder:historyList")
    @PostMapping("/historyList")
    @ResponseBody
    public TableDataInfo historyList(@RequestParam Map<String,Object> params)
    {
        startPage();
        List<Map<String,Object>> list = profitSbOrderService.getOrderPageList(params);
        return getDataTable(list);
    }

    @RequiresPermissions("agentInfo:profitSbOrder:allPayList")
    @GetMapping("/allPayList")
    public String allPayList(ModelMap mmap) throws Exception {
        return prefix + "/allPayList";
    }

    @RequiresPermissions("agentInfo:profitSbOrder:cashbackList")
    @GetMapping("/cashbackList")
    public String cashbackList()
    {
        return prefix + "/cashbackList";
    }
    /**
     * 分润返现列表
     */
    @RequiresPermissions("agentInfo:profitSbOrder:cashbackList")
    @PostMapping("/cashbackList")
    @ResponseBody
    public TableDataInfo listMap(@RequestParam Map<String,Object> param)
    {
        startPage();
        List<Map<String,Object>> maps = profitSbOrderService.getCallbackList(param);
        return getDataTable(maps);
    }



    /**
     * 分润返现列表汇总
     */
    @RequiresPermissions("agentInfo:profitSbOrder:cashbackList")
    @PostMapping("/cashbackListSum")
    @ResponseBody
    public TableDataInfo listMapSum(@RequestParam Map<String,Object> param)
    {
        List<Map<String,Object>> maps = null;
        try {
            maps = profitSbOrderService.getCallbackListSum(param);
        }catch (Exception e){
            maps = new ArrayList<>();
        }
        return getDataTable(maps);

    }

    /**
     * 提现奖励明细查询
     * @Param [param]
     * @Return com.hjm.framework.web.domain.AjaxResult
     */
    @RequiresPermissions("agentInfo:profitSbOrder:withdrawalDetail")
    @Log(title = "失败重新出款", businessType = BusinessType.UPDATE)
    @PostMapping( "/withdrawalDetail")
    @ResponseBody
    public AjaxResult withdrawalDetail(MerPaid merPaid) throws Exception {

        return AjaxResult.success("出款处理中.....");
    }

    /**
     * 结算导出
     * @param params
     * @return
     * @throws Exception
     */
    @RequestMapping("/exportSettleInfo")
    @ResponseBody
    public AjaxResult exportSettleInfo(@RequestParam Map params) throws Exception {
        //查询未出款的数据
        params.put("settle_state",0);
        //0-未出款数据菜单、1-所有出款数据
        if(null==params.get("searchType")) {
            params.put("searchType",0);
        }

        String money = String.valueOf(params.get("lower_money"));
        if (StringUtils.isNotBlank(money)){
            Boolean strResult = money.matches("-?[0-9]+.*[0-9]*");
            if (!strResult){
                params.remove("lower_money");
                params.put("no_date","1");
            }
        }
        List<Map<String,Object>> lists = profitSbOrderService.getUnPayPageList(params);
        List<AgentPaiWVO> list = new ArrayList<>();
        for (Map<String, Object> data : lists) {
            data.put("PROFIT_TYPE", PublicTypeUtils.getTypeStr(data.get("PROFIT_TYPE")));
            data.put("AGENT_TYPE", PublicTypeUtils.getPosType(data.get("AGENT_TYPE")));
            String jsonString = JSONObject.toJSONString(data);
            AgentPaiWVO mp = JSON.parseObject(jsonString, AgentPaiWVO.class);
            list.add(mp);
        }
        ExcelUtil excelUtil = new ExcelUtil(AgentPaiWVO.class);
        return  excelUtil.exportExcel(list, "分润未出款" + DateUtils.dateTimeNow());
    }
}
